home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-06-24 | 3.2 KB | 131 lines | [TEXT/MPS ] |
- // Copyright © 1994-95 by Apple Computer, Inc. All rights reserved.
- // UShapeList.cp
-
- #ifndef __USHAPELIST__
- #include "UShapeList.h"
- #endif
-
- //========================================================================================
- // CLASS TShapeList
- //========================================================================================
- #undef Inherited
- #define Inherited TList
-
- #pragma segment ShapeList
- MA_DEFINE_CLASS_M1(TShapeList, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TShapeList Constructor - empty
- //----------------------------------------------------------------------------------------
- #pragma segment ShapeList
-
- TShapeList::TShapeList()
- {
- }
-
- //----------------------------------------------------------------------------------------
- #pragma segment ShapeList
-
- TShape* TShapeList::ShapeAt(ArrayIndex index)
- {
- /* Range checking? */
- return (TShape*)this->At(index);
- }
-
- //----------------------------------------------------------------------------------------
- #pragma segment ShapeList
-
- void TShapeList::Each(DoToShapeType DoToShape, void* staticLink)
- {
- CShapeIterator iter(this);
-
- for (TShape* shape = iter.FirstShape(); iter.More(); shape = iter.NextShape())
- DoToShape(shape, staticLink);
- }
-
- //----------------------------------------------------------------------------------------
- #pragma segment ShapeList
-
- TShape* TShapeList::FirstThat(TestShapeType TestShape, void* staticLink)
- {
- ArrayIndex index;
-
- return this->IterateTil(TestShape, staticLink, kIterateForward, index);
- }
-
- //----------------------------------------------------------------------------------------
- #pragma segment ShapeList
-
- TShape* TShapeList::IterateTil(TestShapeType TestShape,
- void* staticLink,
- Boolean IterateForward,
- ArrayIndex& itsIndex)
- {
- TShape* shape = NULL;
-
- {
- CArrayIterator iter(this, IterateForward);
-
- for (itsIndex = iter.FirstIndex(); iter.More(); itsIndex = iter.NextIndex())
- {
- TShape* testShape = this->ShapeAt(itsIndex);
- if (TestShape(testShape, staticLink))
- {
- shape = testShape;
- break;
- }
- }
- }
-
- return shape;
- } // TShapeList::IterateTil
-
- //========================================================================================
- // CLASS CShapeIterator
- //========================================================================================
- #pragma segment ShapeList
-
- CShapeIterator::CShapeIterator(TShapeList* itsList, Boolean itsForward) :
- CArrayIterator(itsList, itsForward)
- {
- }
-
- CShapeIterator::CShapeIterator(TShapeList* itsList,
- ArrayIndex itsLowBound,
- ArrayIndex itsHighBound,
- Boolean itsForward) :
- CArrayIterator(itsList, itsLowBound, itsHighBound, itsForward)
- {
- }
-
- TShape* CShapeIterator::CurrentShape()
- {
- if (this->More())
- return ((TShapeList *)fDynamicArray)->ShapeAt(fCurrentIndex);
- else
- return NULL;
- }
-
- TShape* CShapeIterator::FirstShape()
- {
- this->Reset();
- if (this->More())
- return ((TShapeList *)fDynamicArray)->ShapeAt(fCurrentIndex);
- else
- return NULL;
- }
-
- TShape* CShapeIterator::NextShape()
- {
- this->Advance();
- if (this->More())
- return ((TShapeList *)fDynamicArray)->ShapeAt(fCurrentIndex);
- else
- return NULL;
- }
-
- CShapeIterator::~CShapeIterator()
- {
- }
-
-